package com.tanker.util.httpUtil;

import java.util.Collection;
import java.util.Map;
import java.util.Set;

/**
 * Created by wen.yan on 2015/6/16.
 */
public class DefaultDataMap implements DataMap, Map<String, Object> {
    private Map<String, Object> map;

    public DefaultDataMap(Map<String, Object> map) {
        this.map = map;
    }

    @Override
    public Object get(String key) {
        return map.get(key);
    }

    @Override
    public int size() {
        return map.size();
    }

    @Override
    public boolean isEmpty() {
        return map.isEmpty();
    }

    @Override
    public boolean containsKey(Object key) {
        return map.containsKey(key);
    }

    @Override
    public boolean containsValue(Object value) {
        return map.containsValue(value);
    }

    @Override
    public Object get(Object key) {
        return map.get(key);
    }

    @Override
    public Object put(String key, Object value) {
        return map.put(key, value);
    }

    @Override
    public Object remove(Object key) {
        return map.remove(key);
    }

    @Override
    public void putAll(Map<? extends String, ?> m) {
        map.putAll(m);
    }

    @Override
    public void clear() {
        map.clear();
    }

    @Override
    public Set<String> keySet() {
        return map.keySet();
    }

    @Override
    public Collection<Object> values() {
        return map.values();
    }

    @Override
    public Set<Entry<String, Object>> entrySet() {
        return map.entrySet();
    }

    @Override
    public String getString(String key) {
        Object value = get(key);
        return value == null ? null : value.toString();
    }

    @Override
    public Integer getInt(String key) {
        String value = getString(key);
        return value == null ? null : Integer.valueOf(value);
    }

    @Override
    public Double getDouble(String key) {
        String value = getString(key);
        return value == null ? null : Double.valueOf(value);
    }

    @Override
    public Boolean getBoolean(String key) {
        String value = getString(key);
        return value == null ? null : ("true".equals(value) || "1".equals(value));
    }

    @Override
    public String toString() {
        return map.toString();
    }

}
